package com.zhangchuchu.neohealth.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangchuchu.neohealth.entity.User;
import com.zhangchuchu.neohealth.mapper.UserMapper;
import com.zhangchuchu.neohealth.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;
    // 判断用户名是否已存在
    @Override
    public boolean existsByUsername(String username) {
        return this.baseMapper.selectCountByUsername(username) > 0;
    }

    // 判断邮箱是否已存在
    @Override
    public boolean existsByEmail(String email) {
        return this.baseMapper.selectCountByEmail(email) > 0;
    }

    // 判断手机号是否已存在
    @Override
    public boolean existsByPhone(String phone) {
        return this.baseMapper.selectCountByPhone(phone) > 0;
    }

    @Override
    public User findByUsername(String username) {
        return userMapper.findByUsername(username);
    }

    @Override
    public User findByEmail(String email) {
        return userMapper.findByEmail(email);
    }

    @Override
    public User findByPhone(String phone) {
        return userMapper.findByPhone(phone);
    }

    @Override
    public boolean updateUser(User user) {
        return this.updateById(user);  // MyBatis-Plus 提供的 update 方法
    }
}
